package april.test_4_12;

import java.util.Scanner;
import java.util.Stack;

import static java.lang.Character.isDigit;

public class TestMain2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int n = scanner.nextInt();
            Stack<Integer> stack = new Stack<>();
            for (int i = 0; i < n; i++) {
                String str = scanner.next();
                int count = 0;
                if (str.charAt(0) == '+') {
                    int a = stack.pop();
                    int b = stack.pop();
                    count = a + b;
                    stack.push(count);
                } else if (str.charAt(0) == '-') {
                    int a = stack.pop();
                    int b = stack.pop();
                    count = a - b;
                    stack.push(count);
                } else if (str.charAt(0) == '*') {
                    int a = stack.pop();
                    int b = stack.pop();
                    count = a * b;
                    stack.push(count);
                } else if (str.charAt(0) == '/') {
                    int a = stack.pop();
                    int b = stack.pop();
                    if(b == 0) {
                        count = 0;
                        return;
                    } else {
                        count = a / b;
                    }
                    stack.push(count);
                } else {
                    count = Integer.parseInt(str);
                    stack.push(count);
                }
            }
            System.out.println(stack.pop());
        }
    }
}
